#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

# pip install MechanicalSoup
import coddVue
import coddJs
import coddForm
from datetime import date, datetime

import os
import shutil
import pandas as pd
import json
from faker import Faker
fake = Faker('zh-CN')

row = {
    "tname": "sysrole",
    "tinfo": "角色表",
    "cols": [
      {
          "cname": "oid",
          "cinfo": "ID",
          "ctype": "bigint"
      },
        {
          "cname": "name",
          "cinfo": "名称",
          "ctype": "varchar(255)"
      },
        {
          "cname": "level",
          "cinfo": "角色级别",
          "ctype": "int"
      },
        {
          "cname": "description",
          "cinfo": "描述",
          "ctype": "varchar(255)"
      },
        {
          "cname": "dataScope",
          "cinfo": "数据权限",
          "ctype": "varchar(255)"
      },


        {
          "cname": "createTime",
          "cinfo": "创建日期",
          "ctype": "datetime"
      }
    ]
}

''' 读取json数据  表的信息
'''


def doRead():
    with open('./input/llbb.json') as f:
        datas = f.read()
        # print(datas)
        return datas


def main():
    # jsonStr = doRead()
    # rows = json.loads(jsonStr)

    # for row in rows:
    #     dirr = './output/llbb/{}'.format(row['tname'].lower())
    #     if not os.path.exists(dirr):
    #         os.mkdir(dirr)
    #     coddVue.toVue(row)
    #     coddJs.toJs(row)

    # row = rows[0]
    # print(row)
    dirr = './output/llbb/{}'.format(row['tname'].lower())
    if not os.path.exists(dirr):
        os.mkdir(dirr)
    coddVue.toVue(row)
    coddJs.toJs(row)
    coddForm.toForm(row)

    api = '''
    
// #sname#Service
export const #sname#Service = {
  queryData: (params = {}) => get(`/#sname#`, params),
  postItem: (params = {}) => {
    return post(`/#sname#`, params);
  },
  deleteItem: params => post(`/#sname#/d`, params),

  getById: params => {
    return get(`/#sname#/${params.id}`, params);
  },
  all: (params = {}) => {
    return get(`/#sname#/all`, params);
  }
 
};

    '''

    with open('./output/llbb/apiService.js', 'w') as f:
        f.write(api.replace('#sname#', row['tname']))


if __name__ == '__main__':

    main()
    # row = ('ACME', 50, 91.5)
    # print(*row, sep="**")
    print('----success')
